package codename.carrot.bomberman;

import sheep.game.Game;
import android.app.Application;
import codename.carrot.bomberman.activity.GameActivity;

/**
 * Application object for the game, keeps track of "global" objects and whatnot.
 * 
 * @author Group A4
 * 
 */
public class AppStorage extends Application {
	
	/**
	 * Name of the preferences of the statistics.
	 */
	public final static String PREFERENCE_NAME = "droidPref";
	/**
	 * The GameState.
	 */
	public static Game droidGame = null;
	/**
	 * The StatePreferenses, used for statistics.
	 */
	public static StatsPreferences droidPref;
	
	/**
	 * Indication that we are debugging the game
	 */
	public static boolean debuggingGame = false;
	/**
	 * Indication if we are running a local test of gameplay.
	 */
    public static boolean testingGamePlay = false;
    /**
     * Activity height of the screen.
     */
    public static int SCREEN_WIDTH;
    /**
     * Activity width of the screen.
     */
    public static int SCREEN_HEIGHT;
    /**
     * Sheep height of the screen.
     */
	public static int SCREEN_WIDTH_GAME;
	/**
	 * Sheep width of the screen.
	 */
	public static int SCREEN_HEIGHT_GAME;
	/**
	 * Time for bomb to fuse (blow up).
	 */
	public static int BOMB_FUSE = 3000;
	/**
	 * Delay after bomb is fused to when the flame is visible.
	 */
	public static int FLAME_DELAY = 100;
	/**
	 * How long a player is immune for flames/explosion after it already has been touch by a flame.
	 */
	public static int PLAYER_DAMAGEIMMUNITY = 3000;
	/**
	 * Size of a tile - calculated by MainActivity.
	 */
	public static int TILE_SIZE = 0;
	/**
	 * Size of an item in the game - calculated by MainActiviy.
	 */
	public static int ITEM_SIZE = 0;
	/**
	 * The size of a player in the game - calculated by MainActiviy.
	 */
	public static int PLAYER_SIZE = 0;
	/**
	 * The activity of the game, for finishing the activity midt game.
	 */
	public static GameActivity gameActivity;
	/**
	 * Indicator of client or a server set up.
	 */
	public static boolean isClient = true;
	/**
	 * 30 degree angle in radiant.
	 */
	private final static double DEGREES_30 = Math.PI / 6d, 
			/**
			 * 60 degree angle in radiant.
			 */
			DEGREES_60 = Math.PI / 3d, 
			/**
			 * 120 degree angle in radiant.
			 */
			DEGREES_120 = 2 * Math.PI / 3d, 
			/**
			 * 150 degree angle in radiant.
			 */
			DEGREES_150 = 5 * Math.PI / 6d;	

	public enum Power {
		/**
		 * Collectible is a power-up.
		 */
	    UP, 
	    /**
	     * Collectible is a power-down.
	     */
	    DOWN
	};
	
	public enum Direction {
		/**
		 * Right direction.
		 */
		RIGHT, 
		/**
		 * Left direction.
		 */
		LEFT, 
		/**
		 * Up direction.
		 */
		UP, 
		/**
		 * Down direction.
		 */
		DOWN, 
		/**
		 * Diagonal upwards to the right.
		 */
		RIGHT_UP,
		/**
		 * Diagonal upwards to the left.
		 */
		LEFT_UP, 
		/**
		 * Diagonal downwards to the right.
		 */
		RIGHT_DOWN, 
		/**
		 * Diagonal downwards to the left.
		 */
		LEFT_DOWN
	}
	
	/**
	 * The direction representation based on an angle.
	 * @param angle The angle to be translated to direction.
	 * @return The direction that the angle represents.
	 */
	public static Direction getDirection(float angle) {
		if (angle <= AppStorage.DEGREES_30 && angle >= AppStorage.DEGREES_30*-1)
			return Direction.RIGHT;
		if (angle <= AppStorage.DEGREES_120 && angle >= AppStorage.DEGREES_60)
			return Direction.DOWN;
		if (angle >= AppStorage.DEGREES_120 * -1 && angle <= AppStorage.DEGREES_60 * -1)
			return Direction.UP;
		if(angle > AppStorage.DEGREES_30 && angle < AppStorage.DEGREES_60)
			return Direction.RIGHT_DOWN;
		if(angle > AppStorage.DEGREES_120 && angle < AppStorage.DEGREES_150)
			return Direction.LEFT_DOWN;
		if(angle < AppStorage.DEGREES_30 * -1 && angle > AppStorage.DEGREES_60 * -1)
			return Direction.RIGHT_UP;
		if(angle < AppStorage.DEGREES_120 * -1 && angle > AppStorage.DEGREES_150 * -1)
			return Direction.LEFT_UP;
		return Direction.LEFT;
	}

}
